package tcos

import (
	"fmt"
	"context"
    "net/url"
    "net/http"
    "github.com/tencentyun/cos-go-sdk-v5"
)

func CreateBucket(appId,region,secretId,secretKey string) {
    addr := "https://" + appId + ".cos." + region + ".myqcloud.com"
    u, _ := url.Parse(addr)
    b := &cos.BaseURL{BucketURL: u}
    c := cos.NewClient(b, &http.Client{
        Transport: &cos.AuthorizationTransport{
            SecretID: secretId,
            SecretKey: secretKey,  
        },
    })
    _, err := c.Bucket.Put(context.Background(), nil)
    if err != nil {
        panic(err)
    }
}

func QueryBucket(secretId,secretKey string) {
	c := cos.NewClient(nil, &http.Client{
        Transport: &cos.AuthorizationTransport{
            SecretID: secretId,
            SecretKey: secretKey,  
        },
    })
    s, _, err := c.Service.Get(context.Background())
    if err != nil {
        panic(err)
    }
    for _, b := range s.Buckets {
        fmt.Printf("%#v\n", b)
    }
}
